package dream.fengxis.app;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {
    private AlertDialog.Builder first_open;
    private Intent i = new Intent();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        first_open = new AlertDialog.Builder(this);
        init();
    }

    private void init() {
        //用以判断程序是否为第一次打开
        if(FileUtil.readFile("/sdcard/.fengxi/user/打开次数.infos").equals("2")){
            //不是第一次打开时执行的代码
            if(FileUtil.readFile("/sdcard/.fengxi/system/设置.settings").contains("Dreams")){
                first_open.setTitle("导入原版本的设置文件");
                first_open.setMessage("我们检测到你的设备中，iFengXi以前的版本曾启动过，并保留了其设置数据，是否要加载？");
                first_open.setPositiveButton("好", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        FileUtil.writeFile("/sdcard/.fengxi/usually/导入设置.infos","y");
                        i.setClass(getApplicationContext(),LoginActivity.class);
                        startActivity(i);
                    }
                });
                first_open.setNegativeButton("不", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        FileUtil.writeFile("/sdcard/.fengxi/usually/导入设置.infos","n");
                        i.setClass(getApplicationContext(),LoginActivity.class);
                        startActivity(i);
                    }
                });
                first_open.setCancelable(false);
                first_open.create().show();
            }
        }else{
            FileUtil.writeFile("/sdcard/.fengxi/usually/导入设置.infos","n");
            i.setClass(getApplicationContext(),LoginActivity.class);
            startActivity(i);
        }
    }
}
